package com.lovo.project.servlet.shop;

import com.lovo.project.exception.OurException;
import com.lovo.project.model.ShopDO;
import com.lovo.project.service.ShopService;
import com.lovo.project.service.impl.ShopServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddShopServlet",value = "/shop/addShop")
public class AddShopServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      try {
        String name = request.getParameter("shopName");
        String licenseNum = request.getParameter("shopLicenseNum");
        String licenseImg = request.getParameter("licenseImg");
        String address = request.getParameter("shopAddress");
        String location = request.getParameter("shopLocation");
        String legalPerson = request.getParameter("shopLegalPerson");
        String phone = request.getParameter("shopPhone");
        String headimg = request.getParameter("headimg");
        String feature = request.getParameter("shopFeature");
        String vipgrade = request.getParameter("shopVipgrade");
        String commissionRate = request.getParameter("shopCommissionRate");
        ShopDO shop = new ShopDO();
        shop.setShopName(name);
        shop.setShopLicenseNum(licenseNum);
        shop.setShopLicenseImg(licenseImg);
        shop.setShopAddress(address);
        shop.setShopLocation(location);
        shop.setShopLegalPerson(legalPerson);
        shop.setShopPhone(phone);
        shop.setShopHeadimg(headimg);
        shop.setShopFeature(feature);
        shop.setShopVipgrade(vipgrade);
        shop.setShopCommissionRate(commissionRate);
        ShopService shopService = new ShopServiceImpl();
        shopService.insertShop(shop);
        response.getWriter().print(ResultVO.success().toJson());
      }catch (OurException o){
        response.getWriter().print(ResultVO.fail(o.getCodeEnum()));
      }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
